<script setup lang="ts">
import { ref, watch } from "vue";
import { useSystemStoreWithOut } from "@/store/modules/system";
import { storeToRefs } from "pinia";

const systemStore = useSystemStoreWithOut();
const { materialTypeList } = storeToRefs(systemStore);

const props = defineProps({
  list: {
    type: Array,
    default: () => []
  },
  tableHeight: {
    type: Number,
    default: 0
  },
  isEdit: {
    type: Boolean,
    default: false
  }
});

const tableData = ref([]);

watch(
  () => props.list,
  (newVal: any) => {
    console.log(newVal);
    tableData.value = newVal;
  },
  { deep: true }
);
</script>

<template>
  <div>
    <el-table
      class="tableBox"
      :data="tableData"
      style="width: 100%"
      :height="tableHeight"
    >
      <el-table-column type="index" label="序号" min-width="100px" />
      <el-table-column
        prop="materialCode"
        label="物料编码"
        min-width="104px"
        show-overflow-tooltip
      />
      <el-table-column
        prop="materialName"
        label="物料名称"
        min-width="160px"
        show-overflow-tooltip
      />
      <el-table-column
        label="物料类型"
        prop="materialType"
        min-width="104px"
        show-overflow-tooltip
      >
        <template #default="scope">
          <el-text>{{
            materialTypeList.find(
              val => val.dictLabelValue == scope.row.materialType
            )?.dictLabelName
          }}</el-text>
        </template>
      </el-table-column>
      <el-table-column
        prop="materialSpecs"
        label="物料规格"
        min-width="160px"
        show-overflow-tooltip
      >
        <template #default="scope">
            <el-text>{{ scope.row.materialSpecsName || scope.row.materialSpecs }}</el-text>
          </template>
        </el-table-column>
      <el-table-column
        prop="unit"
        label="单位"
        min-width="80px"
        show-overflow-tooltip
      />
      <el-table-column
        prop="num"
        label="入库数量"
        min-width="152px"
        show-overflow-tooltip
      />
    </el-table>
  </div>
</template>
<style lang="scss" scoped>
.tableBox {
  .el-input {
    --el-input-width: 100% !important;
  }
}
</style>
